package com.haiheng.voiceandbook.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.haiheng.voiceandbook.R;
import com.haiheng.voiceandbook.view.PwdEditText;


/**
 * @Des: 密码输入弹框
 * @Author: hwz
 * @Date:2021/8/26 0026
 * @Version: 1.0
 */
public class AdminPasswordDialog extends BaseDialog {

//    ModuleReaderAdminPasswordDialogBinding binding = null;
    private TextView tvDialogLeft,tvDialogRight,tvDialogTitle;
    private PwdEditText pwdEditText;
    private OnPasswordLisener onPasswordLisener;

    public OnPasswordLisener getOnPasswordLisener() {
        return onPasswordLisener;
    }

    public void setOnPasswordLisener(OnPasswordLisener onPasswordLisener) {
        this.onPasswordLisener = onPasswordLisener;
    }


    public AdminPasswordDialog(Context context) {
        super(context, R.style.dialog_with_slide_anim);
        initData();
        setGravity(Gravity.CENTER);
        setCanceledOnTouchOutside(false);
    }



    public void setDialogTitle(String title) {
        tvDialogTitle.setText(title);
    }

    public void clearText(){
        pwdEditText.clearText();
    }

    private void initData() {
//        binding = DataBindingUtil.inflate(LayoutInflater
//                .from(getContext()),R.layout.module_reader_admin_password_dialog,null,false);
        setContentView(R.layout.admin_password_dialog);
        tvDialogTitle = findViewById(R.id.tvTitle);
        tvDialogLeft = findViewById(R.id.tvDialogLeft);
        pwdEditText = findViewById(R.id.pwdEditText);
        tvDialogRight = findViewById(R.id.tvDialogRight);
        tvDialogLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        tvDialogRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onPasswordLisener != null){
                    onPasswordLisener.onRightClick(tvDialogTitle.getText().toString(),pwdEditText.getPwdText());
                }
            }
        });
    }

    public interface OnPasswordLisener{
        void onRightClick(String title,String passwod);
    }
}
